*This file contains code to create Tables 2, 3, 4, 8, A6, A7, A8 and Figures 1, 2, 3, A1, A2, A3, A9, A11, A12

use data_IL.dta, clear


*create tract-level measures of SNAP useage
sum per_snap, d
scalar per_snap_mean = r(mean)
scalar per_snap_med = r(p50)

g snap_high = per_snap > `=per_snap_med'

*create tract-level measures of SNAP stores
sum stores_count, d
scalar store_snap_mean = r(mean)
scalar store_snap_med = r(p50)

g store_high = stores_count > `=store_snap_med'

*create RD variables
g post = (1-pre)
g run_var = date_m - 18294
g run_var_post = post*run_var

foreach var in run_var run_var_post{
g `var'_2 = `var'^2
g `var'_3 = `var'^3
}

g daytype_r1 = (day == 1)
g daytype_r2_23 = (day > 1 & day < 24)
g daytype_r24_31 = (day > 23)
g daytype_r = daytype_r1 ==1
		replace daytype_r = 2 if daytype_r2_23 == 1
		replace daytype_r = 3 if daytype_r24_31 == 1

sort year month
g year_month = (year*100) + month
egen month_id = group(year_month)
bys month_id: egen m2 = min(run_var)
drop month_id
rename m2 month_id

egen ct_id = group(geo_id)

*create weather controls
local weather prcp snwd snow tmax tmin awnd

*create titles for figures
scalar ti_any= "Crime"
scalar ti_theft_grocery = "Theft at Grocery Stores"
scalar ti_grocery = "Crime at Grocery Stores"
scalar ti_theft = "Theft"
scalar ti_prcp= "Precipitation"
scalar ti_snwd= "Snow Depth"
scalar ti_snow= "Snow (in Inches)"
scalar ti_tmax="Max Temperature"
scalar ti_tmin="Min Temperature"
scalar ti_awnd="Wind"
scalar ti_SNAP_Spending = "SNAP Redemptions"

label var any "Crime"
label var theft_grocery "Theft at Grocery Stores"
label var grocery "Crime at Grocery Stores"
label var theft "Theft"
label var SNAP_Spending "SNAP Redemptions"

*MSE-optimal bandwidths for uniform kernel
local bw_any "if abs(run_var)<45"
local bw_theft "if abs(run_var)<142"
local bw_theft_grocery "if abs(run_var)<244"
local bw_grocery "if abs(run_var)<302"
local bw_anycutoff "45"
local bw_theftcutoff "142"
local bw_theft_grocerycutoff "244"
local bw_grocerycutoff "302"

**creating tables and graphs
loc REG_estout "substitute(_ \_ { $\left\{\text{ } }\right\}$) la collabels(none) eqlabels(none) posthead("") mlabels(none) prefoot("") postfoot("") varwidth(16) modelwidth(12) style(tex) starl(* .10 ** 0.05 *** 0.01)"

*********************
*****MAKE TABLES*****
*********************


***Table 2: Summary Statistics (Panel A)

label var any "Crime"
label var theft "Theft"
label var grocery "Crimes at Grocery Stores"
label var theft_grocery "Theft at Grocery Stores"
label var per_snap "Percent Household on SNAP (2010)"
label var stores_count "Number of SNAP Retailers (2010)"

estpost sum any theft grocery theft_grocery per_snap stores_count, listwise  
estout using "ILsum.tex", cells("mean (fmt(%6.3fc 3)) sd (fmt(%6.3fc 3)) ") `REG_estout' replace


***Table 3: Main Results
eststo clear
set more off
preserve
g daytype_r2 = daytype_r2_23 
g daytype_r3 = daytype_r24_31 

forvalues d = 1/3{
g post_day`d' = post*daytype_r`d'
g runvar`d' =  run_var*daytype_r`d'
g runvarpost`d' = runvar`d'*post
}

foreach t in any grocery theft theft_grocery {
eststo fullct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day, vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

eststo mainct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day `bw_`t'', vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0 & run_var>-`bw_`t'cutoff'
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'
*
forvalues r = 1/3{
eststo rangect`r'_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day `bw_`t'' & daytype_r == `r', vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0 & daytype_r == `r' & run_var>-`bw_`t'cutoff'
scalar mean`t'_r`r' = round(r(mean),0.001)
di mean`t'_r`r'
estadd scalar ppmean= mean`t'_r`r'
}
}

	estout fullct_tany mainct_tany rangect1_tany rangect2_tany rangect3_tany using "t3_any.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_ttheft mainct_ttheft rangect1_ttheft rangect2_ttheft rangect3_ttheft using "t3_theft.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_tgrocery mainct_tgrocery rangect1_tgrocery rangect2_tgrocery rangect3_tgrocery using "t3_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_ttheft_grocery mainct_ttheft_grocery rangect1_ttheft_grocery rangect2_ttheft_grocery rangect3_ttheft_grocery using "t3_theft_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) `REG_estout' keep(post) varlabels(post "SNAP Staggered")
	eststo clear
restore


***Table 4: Neighborhood Subgroups
eststo clear
set more off

foreach t in any grocery theft theft_grocery {
eststo mainct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.day i.dow `bw_`t'', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 
scalar mean`t' = round(r(mean),0.001)
di mean`t'


foreach type in snap store{
forvalues ct = 0/1{
eststo ct_`type'`ct'_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.day i.dow `bw_`t'' & `type'_high == `ct', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 & `type'_high == `ct'
scalar mean`t'_`type'`ct' = round(r(mean),0.001)
di mean`t'_`type'`ct'
estadd scalar ppmean= mean`t'_`type'`ct'
}
}
}

estout *tany* using "geo_any.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
estout *ttheft using "geo_theft.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
estout *tgrocery using "geo_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")  
estout *ttheft_grocery* using "geo_theft_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")


***Table 7: Robustness Checks
xtset ct_id 
set more off
eststo clear
*note: we rename the post variable to get it to align in the .tex table with rdrobust output
rename post RD_Estimate
foreach t in any theft grocery theft_grocery {
eststo rob_`t'base: xi: areg `t' RD_Estimate run_var run_var_post `weather' i.year i.day i.dow, vce(cluster ct_id) absorb(ct_id)
eststo rob_`t'2: xi: areg `t' RD_Estimate run_var run_var_post run_var_2 run_var_post_2 `weather' i.day i.year i.dow, vce(cluster ct_id) absorb(ct_id)
eststo rob_`t'3: xi: areg `t' RD_Estimate run_var run_var_post run_var_2 run_var_post_2 run_var_3 run_var_post_3 `weather' i.day i.year i.dow, vce(cluster ct_id) absorb(ct_id)
eststo rob_`t'poi: xi: xtpoisson `t' RD_Estimate run_var run_var_post  `weather' i.year i.dow i.day, fe vce(r) nolog
}

***Triangular
forvalues m = 2/12{
g month_`m' = 0
	replace month_`m' = 1 if month == `m'
}
forvalues d = 1/6{
g dow_`d' = 0
	replace dow_`d' = 1 if dow == `d'
}
forvalues y = 2008/2013{
g year_`y' = 0
	replace year_`y' = 1 if year == `y'
}
forvalues k=1/31{
g day_`k'=0
	replace day_`k'=1 if day==`k'
}
local dayofmonthFEs day_1 day_2 day_3 day_4 day_4 day_5 day_6 day_7 day_8 day_9 day_10 day_11 day_12 day_13 day_14 day_15 day_16 day_17 day_18 day_19 day_20 day_21 day_22 day_23 day_24 day_25 day_26 day_27 day_28 day_29 day_30
local dowFEs dow_1 dow_2 dow_3 dow_4 dow_5 dow_6
local yearFEs year_2008 year_2009 year_2010 year_2011 year_2012 year_2013

foreach t in any theft grocery theft_grocery {
rdbwselect `t' run_var, kernel(tri) 
scalar `t'_bw = e(h_mserd)
di `t'_bw = e(h_mserd)
reg `t' RD_Estimate run_var run_var_post `weather' dow_1 dow_2 dow_3 dow_4 dow_5 dow_6 if abs(run_var) < `=`t'_bw'
eststo rob_`t'tri_2: rdrobust `t' run_var, kernel(tri) h(1186) covs(`weather' dow_1 dow_2 dow_3 dow_4 dow_5 dow_6 year_2008 year_2009 year_2010 year_2011 year_2012 year_2013)
eststo rob_`t'tri_1: rdrobust `t' run_var, kernel(tri) h(`=`t'_bw') covs(`weather' dow_1 dow_2 dow_3 dow_4 dow_5 dow_6)
}


estout rob_any* using "rob_any.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' keep(RD_Estimate) varlabels(post "SNAP Staggered")
estout rob_theftbase rob_theft2 rob_theft3 rob_theftpoi rob_theftt* using "rob_theft.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' keep(RD_Estimate) varlabels(post "SNAP Staggered")
estout rob_grocery* using "rob_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' keep(RD_Estimate) varlabels(post "SNAP Staggered")
estout rob_theft_grocery* using "rob_theft_grocery.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' keep(RD_Estimate) varlabels(post "SNAP Staggered")

rename RD_Estimate post


***Table A6: Weekend SNAP Receipt
eststo clear
set more off

g daytype_r2 = daytype_r2_23 
g daytype_r3 = daytype_r24_31 

forvalues d = 1/3{
g post_day`d' = post*daytype_r`d'
g runvar`d' =  run_var*daytype_r`d'
g runvarpost`d' = runvar`d'*post
}
g weekend=0
replace weekend=1 if dow==5| dow==6

g SNAPday=0
replace SNAPday=1 if dom==1 | dom==3 | dom==4 | dom==7 | dom==8 | dom==10 | dom==11 | dom==14 | dom==17 | dom==19 | dom==21 | dom==23
g interact_weekend=weekend*SNAPday


foreach t in any grocery theft theft_grocery {
eststo fullct_t`t': xi: areg `t' post run_var run_var_post interact_weekend `weather' i.year i.dow i.day, vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

eststo mainct_t`t': xi: areg `t' post run_var run_var_post interact_weekend `weather' i.year i.dow i.day `bw_`t'', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'
*
forvalues r = 1/3{
eststo rangect`r'_t`t': xi: areg `t' post run_var run_var_post interact_weekend `weather' i.year i.dow i.day `bw_`t'' & daytype_r == `r', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 & daytype_r == `r'
scalar mean`t'_r`r' = round(r(mean),0.001)
di mean`t'_r`r'
estadd scalar ppmean= mean`t'_r`r'
}
}

	estout fullct_tany mainct_tany rangect1_tany rangect2_tany rangect3_tany using "t3_any_weekendSNAP.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_weekend) varlabels(post "SNAP Staggered" interact_weekend "Weekend SNAP")
	estout fullct_ttheft mainct_ttheft rangect1_ttheft rangect2_ttheft rangect3_ttheft using "t3_theft_weekendSNAP.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_weekend) varlabels(post "SNAP Staggered" interact_weekend "Weekend SNAP")
	estout fullct_tgrocery mainct_tgrocery rangect1_tgrocery rangect2_tgrocery rangect3_tgrocery using "t3_grocery_weekendSNAP.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_weekend) varlabels(post "SNAP Staggered" interact_weekend "Weekend SNAP")
	estout fullct_ttheft_grocery mainct_ttheft_grocery rangect1_ttheft_grocery rangect2_ttheft_grocery rangect3_ttheft_grocery using "3_theft_grocery_weekendSNAP.tex", replace c(b(star fmt(4)) se(par fmt(4))) stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) `REG_estout' keep(post interact_weekend) varlabels(post "SNAP Staggered" interact_weekend "Weekend SNAP")
	eststo clear


***Table A7: Weekend Paydays
g payday=0
replace payday=1 if dom==1 | dom==15
g interact_payday=weekend*payday
foreach t in any grocery theft theft_grocery {
eststo fullct_t`t': xi: areg `t' post run_var run_var_post interact_payday `weather' i.year i.dow i.day, vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'
eststo mainct_t`t': xi: areg `t' post run_var run_var_post interact_payday `weather' i.year i.dow  i.day `bw_`t'', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

forvalues r = 1/3{
eststo rangect`r'_t`t': xi: areg `t' post run_var run_var_post interact_payday `weather' i.year i.dow i.day `bw_`t'' & daytype_r == `r', vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 & daytype_r == `r'
scalar mean`t'_r`r' = round(r(mean),0.001)
di mean`t'_r`r'
estadd scalar ppmean= mean`t'_r`r'
}
}

	estout fullct_tany mainct_tany rangect1_tany rangect2_tany rangect3_tany using "t3_any_weekendpayday.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_payday) varlabels(post "SNAP Staggered" interact_payday "Weekend Payday")
	estout fullct_ttheft mainct_ttheft rangect1_ttheft rangect2_ttheft rangect3_ttheft using "t3_theft_weekendpayday.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_payday) varlabels(post "SNAP Staggered" interact_payday "Weekend Payday")
	estout fullct_tgrocery mainct_tgrocery rangect1_tgrocery rangect2_tgrocery rangect3_tgrocery using "t3_grocery_weekendpayday.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post interact_payday) varlabels(post "SNAP Staggered" interact_payday "Weekend Payday")
	estout fullct_ttheft_grocery mainct_ttheft_grocery rangect1_ttheft_grocery rangect2_ttheft_grocery rangect3_ttheft_grocery using "t3_theft_grocery_weekendpayday.tex", replace c(b(star fmt(4)) se(par fmt(4))) stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) `REG_estout' keep(post interact_payday) varlabels(post "SNAP Staggered" interact_payday "Weekend Payday")
	eststo clear

***Table A8: Supermarkets
eststo clear
set more off


foreach t in any grocery theft theft_grocery {
eststo fullct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day if supermarkets>0, vce(cluster ct_id) absorb(ct_id)
sum `t' if post == 0
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'


eststo mainct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day `bw_`t'' & supermarkets>0, vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' &  post == 0 
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

forvalues r = 1/3{
eststo rangect`r'_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day `bw_`t'' & daytype_r == `r' & supermarkets>0, vce(cluster ct_id) absorb(ct_id)
sum `t' `bw_`t'' & post == 0 & daytype_r == `r' 
scalar mean`t'_r`r' = round(r(mean),0.001)
di mean`t'_r`r'
estadd scalar ppmean= mean`t'_r`r'
}
}


	estout fullct_tany mainct_tany rangect1_tany rangect2_tany rangect3_tany using "t3_any_supermarkets.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_ttheft mainct_ttheft rangect1_ttheft rangect2_ttheft rangect3_ttheft using "t3_theft_supermarkets.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_tgrocery mainct_tgrocery rangect1_tgrocery rangect2_tgrocery rangect3_tgrocery using "t3_grocery_supermarkets.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout fullct_ttheft_grocery mainct_ttheft_grocery rangect1_ttheft_grocery rangect2_ttheft_grocery rangect3_ttheft_grocery using "t3_theft_grocery_supermarkets.tex", replace c(b(star fmt(4)) se(par fmt(4))) stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) `REG_estout' keep(post) varlabels(post "SNAP Staggered")
	eststo clear
	

**********************
*****MAKE FIGURES*****
**********************

***Figure 1: Illinois SNAP Disbursement Change on Crime
foreach t in grocery theft theft_grocery  { 
preserve
keep if abs(run_var)<`bw_`t'cutoff'
xi: areg `t' `weather', r absorb(ct_id)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id <0) (lfitci `t'_resid_mon_ct run_var if month_id >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" 120 "Jun 2010" -123 "Oct 2009") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "ct_rdd_`t'.png", replace;
#delimit cr
restore
}

foreach t in any  { 
preserve
keep if run_var<45 & run_var>-45
replace month_id=-45 if run_var>-45 & run_var<-31
xi: areg `t' `weather' if abs(run_var)<`bw_`t'cutoff', r absorb(ct_id)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id<0) (lfitci `t'_resid_mon_ct run_var if month_id>=0) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" -31 "Jan 2010" 28 "Mar 2010") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "ct_rdd_any.png", replace;
#delimit cr
restore
}


***Figure 2: SNAP Redemptions
preserve
use "SNAP_reimburse.dta", clear
collapse (sum) SNAP_Spending, by(month year)
rename SNAP_Spending SNAP_Spending_month
merge 1:m month year using "SNAP_reimburse.dta"
drop _merge
g post = (1-pre)
g run_var = date_m - 18294
g run_var_post = post*run_var

foreach var in run_var run_var_post{
g `var'_2 = `var'^2
g `var'_3 = `var'^3
}


sort year month
g year_month = (year*100) + month
egen month_id = group(year_month)
bys month_id: egen m2 = min(run_var)

drop month_id
rename m2 month_id

g SNAP_pct= (SNAP_Spending/ SNAP_Spending_month)*100
bys day pre: egen mean_spend_pct_day = mean(SNAP_pct) 


#delimit ;
twoway (scatter mean_spend_pct_day day if pre == 1, connect(l) msymbol(none)) (scatter mean_spend_pct_day day if pre == 0, connect(l) clpattern(dash) msymbol(none)), ti(Percent SNAP reimbursements by Day of Month, margin(b=2)) legend(label(1 "SNAP on 1st") label(2 "SNAP on 2-23")) 
	yti("Means", margin(r = 2)) xti("Day of Month", margin(t = 2 b = 2)) xline(2 23)  graphregion(color(white) lc(white)) ylabel(,nogrid)
	t1title(" 1st            distributed after policy change              never disbursed", margin(t=3))
;
#delimit cr
graph export "reimburse_pct.png", replace
restore


***Figure 3: Crime by Day of Month

foreach t in any grocery theft theft_grocery{ 		
xi: reg `t' i.year i.month, r
predict `t'_resid_yrmon, r
		
bys day pre: egen mean_`t'_day = mean(`t'_resid_yrmon)
#delimit ;
twoway (lpoly mean_`t'_day day if pre == 1, lp(dash)) (lpoly mean_`t'_day day if pre == 0), ti(`=ti_`t'' by Day of Month, margin(b=2)) legend(label(1 "SNAP on 1st") label(2 "SNAP on 2-23")) 
	yti("Residualized Means", margin(r = 2)) xti("Day of Month", margin(t = 2 b = 2)) xline(2 23)  graphregion(color(white) lc(white)) 
	t1title(" 1st            distributed after policy change              never disbursed", margin(t=3))
;
#delimit cr
graph export "dom_`t'_Indiana.png", replace

}



***Figure A1: Illinois Dibursement Change on Crime: Full Bandwidth 
foreach t in any  grocery theft theft_grocery { 
preserve
xi: areg `t' `weather', r absorb(ct_id)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id <0) (lfitci `t'_resid_mon_ct run_var if month_id >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" -365 "Feb 2009" -730 "Feb 2008" -1095 "Feb 2007"  365 "Feb 2011" 730 "Feb 2012" 1095 "Feb 2013") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "ct_rdd_`t'_fullbw.png", replace;
#delimit cr
restore
}


***Figure A2: Effect of Illinois Disbursement Change on Crime: No Residualizing
foreach t in any grocery theft theft_grocery  { 
preserve
keep `bw_`t''
bys month_id: egen mean_`t'_ct = mean(`t') 

#delimit ;
twoway (lfitci `t' run_var if month_id <0) (lfitci `t' run_var if month_id >-1) 
(scatter mean_`t'_ct month_id if month_id <0) (scatter mean_`t'_ct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel(0 "Feb 2010" -365 "Feb 2009" 365 "Feb 2011") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "noresid_`t'.png", replace;
#delimit cr
restore
}

***Figure A3: Total SNAP redemptions
preserve
use "SNAP_reimburse.dta", clear

g post = (1-pre)
g run_var = date_m - 18294
g run_var_post = post*run_var

foreach var in run_var run_var_post{
g `var'_2 = `var'^2
g `var'_3 = `var'^3
}


sort year month
g year_month = (year*100) + month
egen month_id = group(year_month)
bys month_id: egen m2 = min(run_var)

drop month_id
rename m2 month_id


xi: reg SNAP_Spending i.month, r
predict spend_resid_mon, r
bys month_id: egen mean_spend_mon = mean(spend_resid_mon) 

#delimit ;
twoway (lfitci spend_resid_mon run_var if month_id <0) (lfitci spend_resid_mon run_var if month_id >-1) 
(scatter mean_spend_mon month_id if month_id <0) (scatter mean_spend_mon month_id if month_id >-1), ti(Total SNAP Reimbursements)  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" -365 "Feb 2009" -730 "Feb 2008"  365 "Feb 2011" 730 "Feb 2012" 1095 "Feb 2013") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "reimburse_total.png", replace;
#delimit cr
restore
*
***Figure A9: Varying Bandwidth
preserve
eststo clear
forvalues b = 1/39{
foreach t in grocery theft_grocery any theft {
eststo mainct_t`t': xi: areg `t' post run_var run_var_post `weather' i.year i.dow i.day if abs(run_var)<(`b'*30), vce(cluster ct_id) absorb(ct_id)
g beta_`t'`b' = _b[post]
g se_`t'`b' = _se[post]
}
}

keep beta* se*

duplicates drop

g id = 1

#delimit ;
reshape long 
beta_grocery se_grocery
beta_theft_grocery se_theft_grocery
beta_any se_any
beta_theft se_theft
, i(id) j(band, string)
;
#delimit cr

destring band, replace force

drop id 

foreach t in any theft grocery theft_grocery  {
g ul_`t'= beta_`t' + (1.96*se_`t')
g ll_`t' = beta_`t' - (1.96*se_`t')
}


foreach t in any theft grocery theft_grocery  {
#delimit ;
twoway rcap ll_`t' ul_`t' band if band > 3, legend(label(1 "95% CI")) || 
	scatter beta_`t' band if band > 3, yline(0, lcolor(black))  legend(label(2 "Coefficient")) xtitle("Bandwidth (months from policy change)", margin(t=2 b=2)) ytitle("Estimated effect", margin(l=2 r=2))
		graphregion(color(white) lc(white))  ti("`=ti_`t''")
	;
graph export "bandfig_`t'.png", replace;

#delimit cr
}

restore

***Figure A11: Effect of Illinois Disbursement Change on Weather
foreach t in prcp snow tmax tmin awnd { 
preserve
xi: areg `t', r absorb(ct_id)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id <0) (lfitci `t'_resid_mon_ct run_var if month_id >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" -365 "Feb 2009" -730 "Feb 2008" -1095 "Feb 2007"  365 "Feb 2011" 730 "Feb 2012" 1095 "Feb 2013") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "ct_rdd_`t'.png", replace;
#delimit cr
restore
}

***Figure A12: Effect of Illinois Disbursement Change on Employment
preserve
use cookcountylabor_data.dta, clear
scalar ti_labor = "Cook County Civilian Labor Force"
scalar ti_unemploy = "Cook County Unemployment Rate"

foreach t in labor unemploy { 		
xi: areg `t' i.month, r absorb(year)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id <0) (lfitci `t'_resid_mon_ct run_var if month_id >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2010" -365 "Feb 2009" -730 "Feb 2008" -1095 "Feb 2007"  365 "Feb 2011" 730 "Feb 2012" 1095 "Feb 2013") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st                               SNAP on 1-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "ct_rdd_`t'.png", replace;
#delimit cr
}
restore
